//
// Created by Hi on 25-8-29.
//

#ifndef PLUGINMANGER_H
#define PLUGINMANGER_H
#include <qmap.h>
#include "header.h"
#include "../plugins/IDataBasePlugin.h"
#include "ISourcePlugin.h"



class PluginManger {

private:
    PluginManger();

public:
    /**
     * 用来加载所有的插件
     * @return
     */
    void loadAllPlugins();


    /**
     * 获取所有的插件
     * @return
     */
    PluginMap getPlugins();

    /**
     * 根据枚举值类型，返回对应的插件，需要进行强转
     * @param type 枚举类型
     * @param pluginName
     * @return QObject指针
     */
    template<typename T>
    T getPluginsByType(ISourcePlugin::E_Plugin_Type type,ISourcePlugin::E_Plugin_Name pluginName);


    static PluginManger& createInstance();


private:
    PluginMap m_plugins;
};

template<typename T>
inline T PluginManger::getPluginsByType(ISourcePlugin::E_Plugin_Type type,ISourcePlugin::E_Plugin_Name pluginName) {

    if (m_plugins.contains(type)) {
        if (m_plugins[type].contains(pluginName)) {
            ISourcePlugin * plugin = m_plugins[type][pluginName];
            return qobject_cast<T>(plugin);
        }
    }
    return nullptr;
}

#endif //PLUGINMANGER_H
